package com.atguigu.yygh.hosp.controller;

import com.atguigu.cmn.client.DictFeignClient;
import com.atguigu.yygh.common.result.Result;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;


/**
 * @author wans
 * @create 2021-11-19 19:02
 */
@RestController
@Api("医院管理接口")
@RequestMapping("/admin/hosp/hospital")
@CrossOrigin
public class HospitalController {
    @Autowired
    private  HospitalService hospitalService;
    @Autowired
    private DictFeignClient dictFeignClient;

    //医院列表带分页
    @GetMapping("list/{page}/{limit}")
    public Result listHosp(@PathVariable Integer page,@PathVariable Integer limit,
                            HospitalQueryVo vo){

        //因为数据在mongodb中，所以返回Page对象，注意是springframe下的而不是mp的
         Page<Hospital> hospPage=hospitalService.selectHospPage(page,limit,vo);
         //获取hos的list集合，将医院等级封装进去
         hospPage.getContent().stream().forEach(item->{
            this.setHospitalHosType(item);
         });
         return Result.ok(hospPage);
    }

    private Hospital setHospitalHosType(Hospital item) {
        String hosType = dictFeignClient.getName("Hostype", item.getHostype());
        String provinceName = dictFeignClient.getName(item.getProvinceCode());
        String districtName = dictFeignClient.getName(item.getDistrictCode());
        String cityName = dictFeignClient.getName(item.getCityCode());

        //放入医院类型，省，地区
        item.getParam().put("hosType",hosType);
        item.getParam().put("Address",provinceName+cityName+districtName);
        return item;
    }
}
